//
//  HMStatusReetweet.swift
//  WymanWeibo
//
//  Created by wyman on 16/4/15.
//  Copyright © 2016年 wyman. All rights reserved.
//

import UIKit

class HMStatusReetweet: UIView {

    
    
    var retweetStatus: HMStatus?{
        didSet{
        
        let reweetName = retweetStatus?.user?.screen_name ?? "被转发用户名称"
            
        let retweetText = retweetStatus?.text ?? "内容为空"
            
            let retweetContent = "@\(reweetName):\(retweetText)"
        retweetLabel.text = retweetContent
            
            //设置配图
            reweetPictureView.pictureURLs = retweetStatus?.storePicutreURLs
            
            reweetPictureView.snp_updateConstraints { (make) in
                let margin = retweetStatus?.storePicutreURLs == nil ? 0 : HMStatusCellMargin
                
                make.top.equalTo(retweetLabel.snp_bottom).offset(margin)
            }
        
        
        }
    
    }
    
    //init
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
    private func prepareUI(){
        addSubview(bkgButton)
        addSubview(retweetLabel)
        addSubview(reweetPictureView)
  
        //添加约束
        //背景按钮
        bkgButton.snp_makeConstraints { (make) in
            
            make.edges.equalTo(self)
        }
    
        //文字约束
        
        
    retweetLabel.snp_makeConstraints { (make) in
        
        make.leading.top.equalTo(self).offset(HMStatusCellMargin)
        make.trailing.equalTo(self).offset(-HMStatusCellMargin)

        }
        
        reweetPictureView.snp_makeConstraints { (make) in
            make.leading.equalTo(self).offset(HMStatusCellMargin)
            
            make.top.equalTo(retweetLabel.snp_bottom).offset(HMStatusCellMargin)
            
            make.size.equalTo(CGSizeZero)
            
        }
        
        //添加底部的约束
        
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(reweetPictureView).offset(HMStatusCellMargin)
        }
    }
    
    

    
    //MARK - 懒加载
    
    //背景按钮
    
    private lazy var bkgButton: UIButton = {
    
        let button = UIButton()
        
        //设置按钮
        button.setBackgroundImage(UIImage.init(named: "retweet_background"), forState: .Normal
        )
        button.setBackgroundImage(UIImage.init(named: "retweet_background_highlighted"), forState: .Highlighted)
        
        return button
    
    }()
    
    //懒加载文字
    private lazy var retweetLabel: UILabel = {
    
     let label = UILabel(fontSize: HMStatusNameFontSize, textColor: UIColor.darkGrayColor())
     label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2*HMStatusCellMargin

        label.numberOfLines = 0
        return label
    }()
    
    //懒加载pictView
    private lazy var reweetPictureView : HMStatuPictureView = HMStatuPictureView()
    
}
